package com.gcph.zhuoba.main.Fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.gcph.zhuoba.R;
import com.gcph.zhuoba.main.activitys.MainActivity;
import com.gcph.zhuoba.player.activitys.Ganhuo1DetailActivity;
import com.gcph.zhuoba.player.activitys.Ganhuo2DetailActivity;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

/**
 * 台球圈-干货首页
 * 
 * @author zhanghejie
 */
public class CircleGanhuoFragment extends Fragment {

	//新闻列表
    private ListView listView;
    
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View circleGanhuoLayout = inflater.inflate(R.layout.layout_circle_ganhuo, container, false);
		//初始化头部按钮
		initBtnGuangchang(circleGanhuoLayout);
		// 初始化头部按钮
		initBtnJiaoan(circleGanhuoLayout);
		
		//初始化干货列表
        listView = (ListView) circleGanhuoLayout.findViewById(R.id.ganhuo_list);
        SimpleAdapter adapter = new SimpleAdapter(circleGanhuoLayout.getContext(),getData(),R.layout.item_ganhuo_list,
                new String[]{"list_img"},
                new int[]{R.id.list_img});
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            	if(0==position)
            	{
            		Intent intent = new Intent(view.getContext(), Ganhuo1DetailActivity.class);
                    startActivity(intent);
            	}else if(1==position)
            	{
            		Intent intent = new Intent(view.getContext(), Ganhuo2DetailActivity.class);
                    startActivity(intent);
            	}
                
            }
        });
		
		return circleGanhuoLayout;
	}
	
	private List<Map<String, Object>> getData() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list_img", R.drawable.ganhuo_item_1);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("list_img", R.drawable.ganhuo_item_2);
        list.add(map);
      
        return list;
    }
	
	/**
	 * 初始化广场按钮点击事件
	 * @param circleMessageLayout
	 */
	public void initBtnGuangchang(View circleMessageLayout){
		Button btnGuangchang=(Button)circleMessageLayout.findViewById(R.id.btn_guangchang);
		btnGuangchang.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//点击消息按钮跳转到消息首页
				FragmentManager fManager=getFragmentManager();
				FragmentTransaction fTransaction=fManager.beginTransaction();
				((MainActivity)getActivity()).hideFragments(fTransaction);
				CircleFragment circleFragment=new CircleFragment();
				fTransaction.replace(R.id.content, circleFragment, "circleFragment");
				fTransaction.commit();
			}
		});
	}
	
	/**
	 * 初始化教案按钮点击事件
	 * @param circleLayout
	 */
	public void initBtnJiaoan(View circleLayout) {
		Button btnJiaoan = (Button) circleLayout.findViewById(R.id.btn_jiaoan);
		btnJiaoan.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 点击干货按钮跳转到干货首页
				FragmentManager fManager = getFragmentManager();
				FragmentTransaction fTransaction = fManager.beginTransaction();
				((MainActivity) getActivity()).hideFragments(fTransaction);
				CircleJiaoanFragment circleJiaoanFragment = new CircleJiaoanFragment();
				fTransaction.replace(R.id.content, circleJiaoanFragment, "circleJiaoanFragment");
				fTransaction.commit();
			}
		});
	}

}